#include <iostream>
#include <vector>
#include <cmath>
#define ll long long

using namespace std;

int in[25],out[25];
ll val[25];
vector<int> g[25];
bool vis[25];

int main(){	

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n,m;
	cin >> n >> m;
	for(int i = 1; i <= n; ++i){
		cin >> val[i];
	}
	
	for(int i = 1; i <= m; ++i){
		int u,v;
		cin >> u >> v;
		++out[u];
		++in[v];
		g[u].push_back(v);
	}
	
	int cnt = n;
	ll omaxi = 0;
	ll allmaxi = 0;
	ll ret = 0;
	
	for(int i = 1; i <= n; ++i){
		if(in[i] == 0 && out[i] == 0){
			vis[i] = true;
			--cnt;
			omaxi = max(omaxi,val[i]);
		}
	}
	
	while(cnt){
		ll maxi = 0;
		vector<int> que;
		for(int i = 1; i <= n; ++i){
			if(vis[i]) continue;
			if(in[i] == 0){
				vis[i] = true;
				--cnt;
				que.push_back(i);
			}
		}
		
		for(auto i : que){
				maxi = max(maxi,val[i]);
				for(auto t : g[i]){
					--in[t];
				}
			}
		
		allmaxi = max(allmaxi,maxi); 
		ret += maxi;
	}
	
	if(omaxi > allmaxi){
		ret += omaxi - allmaxi;
	}
	
	cout << ret;
	
	return 0;
}

